/** prjCtrl的日历扩展,太长的逻辑写这里 */
define(['./../../service/daterangeLocale'], function () {
    var app = angular.module('App');
    app.controller('prjCtrl.calendar', ['$scope', 'daterangeLocale', function ($scope, daterangeLocale) {
        $scope.startDate = {
            string: "上上次观测",
            date: null
        };
        $scope.endDate = {
            string: "上一次观测",
            date: null
        };
        $('#date1').daterangepicker({
            singleDatePicker: true,
            startDate: moment().subtract(1, 'months'),
            showDropdowns: true,
            opens: 'left',
            "locale": daterangeLocale
        });
        $('#date1').on('apply.daterangepicker', function (ev, picker) {
            $scope.$apply(function () {
                $scope.startDate = {
                    string: picker.startDate.format('YYYY-MM-DD'),
                    date: picker.startDate
                };
            });
        });
        $('#date2').on('apply.daterangepicker', function (ev, picker) {
            $scope.$apply(function () {
                $scope.endDate = {
                    string: picker.startDate.format('YYYY-MM-DD'),
                    date: picker.startDate
                };
            });
        });
        $('#date2').daterangepicker({
            singleDatePicker: true,
            opens: 'left',
            startDate: moment(),
            showDropdowns: true,
            "locale": daterangeLocale
        });
        $scope.searchClick = function () {
            if (!$scope.startDate.date || !$scope.endDate.date) {
                toastr.error('必须要手动指定起始和终止日期', '日期错误', { timeOut: 5000, "positionClass": "toast-bottom-right", "closeButton": true })
                return;
            } else {
                $scope.search();
            }

        }
    }]);
});